package com.xls.box2023.tuiguangtuandui;


import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzz.bottomencapsulation.customview.statelayout.StateLayout;
import com.lzz.bottomencapsulation.statusbar.StatusBarHeightView;
import com.lzz.bottomencapsulation.utils.TimeUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xls.box2023.Consts.IntentConsts;
import com.xls.box2023.R;
import com.xls.box2023.customcontrol.RoundedImageView;
import com.xls.box2023.entity.AppTeamUsersEntity;
import com.xls.box2023.mvp.MVPBaseActivity;
import com.xls.box2023.utils.SPUtils;
import com.xls.xrecyclerview.XRecyclerView;

import androidx.recyclerview.widget.LinearLayoutManager;


/**
 * MVPPlugin
 */

public class TuiGuangTuanDuiActivity extends MVPBaseActivity<TuiGuangTuanDuiContract.View, TuiGuangTuanDuiPresenter> implements TuiGuangTuanDuiContract.View, View.OnClickListener {

    private TextView title_text;
    private TextView title_back;
    private RelativeLayout title_rl;
    private StatusBarHeightView title_rl_content;
    private XRecyclerView tgtd_list;
    private RoundedImageView tgtd_head;
    private TextView tgtd_name;
    private TextView tgtd_jinrishouyi;
    private TextView tgtd_zongshouyi;

    private TextView tgtd_zongshouyi_mingxi;
    private StateLayout tgtd_statelayout;

    public static void start(Activity homeActivity,String startTime,String stopTime,String refferScoreTotal) {
        Intent intent=new Intent(homeActivity,TuiGuangTuanDuiActivity.class);
//        开始时间2024年1月1日  00：00:00  至当前日期 23：59:59   为总收益
        intent.putExtra(IntentConsts.StartTime,startTime);
        intent.putExtra(IntentConsts.StopTime,stopTime);
        intent.putExtra(IntentConsts.refferScoreTotal,refferScoreTotal);
        homeActivity.startActivity(intent);
    }

    @Override
    public int getView() {
        return R.layout.activity_tuiguangtuandui;
    }

    @Override
    public void initView() {
        title_text = findViewById(R.id.title_text);
        title_back = findViewById(R.id.title_back);
        title_rl = findViewById(R.id.title_rl);
        title_rl_content = findViewById(R.id.title_rl_content);
        tgtd_list = findViewById(R.id.tgtd_list);
        title_text.setText("推广团队");

        tgtd_head = findViewById(R.id.tgtd_head);
        tgtd_name = findViewById(R.id.tgtd_name);
        tgtd_jinrishouyi = findViewById(R.id.tgtd_jinrishouyi);
        tgtd_zongshouyi = findViewById(R.id.tgtd_zongshouyi);

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheInMemory(false)// 设置下载的图片是否缓存在内存中
                .cacheOnDisk(true)// 设置下载的图片是否缓存在SD卡中
                .build();
        ImageLoader.getInstance().displayImage(SPUtils.getUserInfo().getAvatar(),tgtd_head, options);

        tgtd_name.setText(SPUtils.getUserInfo().getNickname());
        title_back.setOnClickListener(this);

        tgtd_statelayout = findViewById(R.id.tgtd_statelayout);

        tgtd_zongshouyi_mingxi=findViewById(R.id.tgtd_zongshouyi_mingxi);

        tgtd_list.setLoadingMoreEnabled(false);
        tgtd_list.setLoadingListener(mPresenter.getLoadingListener());
        tgtd_list.setLayoutManager(new LinearLayoutManager(this));
        tgtd_list.setAdapter(mPresenter.getAdapter());
        tgtd_statelayout.showProgressView();
        tgtd_statelayout.setErrorAndEmptyAction(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tgtd_list.refresh();
            }
        });

        tgtd_zongshouyi_mingxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TuiGuangTuanDuiActivity.start(TuiGuangTuanDuiActivity.this,"2023-10-01",TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()),"");
            }
        });

//        if (TextUtils.equals(mPresenter.getStartTime(),"2023-10-01")&&TextUtils.equals(mPresenter.getStopTime(), TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()))){
//            tgtd_jinrishouyi.setVisibility(View.GONE);
//            tgtd_zongshouyi_mingxi.setVisibility(View.GONE);
//        }else {
//            tgtd_jinrishouyi.setVisibility(View.VISIBLE);
//            tgtd_zongshouyi_mingxi.setVisibility(View.VISIBLE);
//        }

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.title_back) {
            finish();
        }
    }

    @Override
    public StateLayout getStatelayout() {
        return tgtd_statelayout;
    }

    @Override
    public XRecyclerView getListView() {
        return tgtd_list;
    }

    @Override
    public void showData(AppTeamUsersEntity appTeamUsersEntity,long num) {
//        if (appTeamUsersEntity!=null){
////            开始时间2024年1月1日  00：00:00  至当前日期 23：59:59   为总收益
//            if (TextUtils.equals(mPresenter.getStartTime(),"2023-10-01")&&TextUtils.equals(mPresenter.getStopTime(), TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()))){
//                tgtd_zongshouyi.setText("总收益：   "+appTeamUsersEntity.getScoreTotalStr()+" 元宝");
//            }else {
//                tgtd_jinrishouyi.setText("今日收益："+appTeamUsersEntity.getScoreTotalStr()+" 元宝");
//                tgtd_zongshouyi.setText("总收益：   "+mPresenter.getrefferScoreTotalStr()+" 元宝");
//            }
//        }
        tgtd_jinrishouyi.setText("团队共："+num+" 人"+"\n昨日新用户："+appTeamUsersEntity.getDayUserTotal()+"人");
        tgtd_zongshouyi.setVisibility(View.VISIBLE);
        tgtd_zongshouyi.setText("昨日日活："+appTeamUsersEntity.getDayUserActTotal()+"人\n昨日推广收益："+appTeamUsersEntity.getDayptUserScoreTotal());
    }

    @Override
    public void showPeopleNum(long num) {

    }
}
